﻿//警告对话框
//作者：kzcui
var zIndex;
function cAlert(iframeSrc, msW, msH) {
    // alert(document.documentElement.scrollTop);
    //alert(top.document.getElementById('indexValue').value);
    var topIndex;
    var objTopIndex = top.document.getElementById('indexValue');
    if (objTopIndex != null) {
        topIndex = objTopIndex.value == '' ? '0' : objTopIndex.value;
    }

    topIndex = parseInt(topIndex);
    objTopIndex.value = topIndex + 10;

    zIndex = topIndex + 1000;

    var msgw, msgh, bordercolor;
    if (msW == '')
        msgw = 400; //提示窗口的宽度
    else
        msgw = msW;
    if (msH == '')
        msgh = 100; //提示窗口的高度
    else
        msgh = msH;
    bordercolor = "#336699"; //提示窗口的边框颜色
    titlecolor = "#99CCFF"; //提示窗口的标题颜色
    backgcolor = "#666"; //后背景颜色

    var sWidth, sHeight;
    //alert(top.document.body.offsetWidth);
    sWidth = top.document.body.offsetWidth;
    sHeight = top.document.body.offsetHeight;

    var bgObj = top.document.createElement("div");

    bgObj.setAttribute('id', 'bgDiv' + zIndex);
    bgObj.style.position = "absolute";
    bgObj.style.top = 0;

    bgObj.style.background = backgcolor; //后背景颜色
    bgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=15,finishOpacity=30)";
    bgObj.style.opacity = "0.5";
    bgObj.style.left = 0;
    bgObj.style.width = sWidth + "px";
    bgObj.style.height = sHeight + "px";
    bgObj.style.zIndex = zIndex;
    bgObj.title = '双击灰色区域可返回上级';
    if (window.attachEvent) {
        //IE 的事件代码
        //bgObj.attachEvent("onclick", function() { closeDIV(zIndex); });
        bgObj.attachEvent("ondblclick", function() { closeDIV(zIndex); });
    }
    else {
        //其它浏览器的事件代码
        //bgObj.addEventListener("click", function() { closeDIV(zIndex); }, false);
        bgObj.addEventListener("dblclick", function() { closeDIV(zIndex); }, false);
    }

    top.document.body.appendChild(bgObj);
    var msgObj = top.document.createElement("div")
    msgObj.setAttribute("id", "msgDiv" + zIndex);
    msgObj.setAttribute("align", "center");
    msgObj.style.position = "absolute";
    msgObj.style.background = "white";
    msgObj.style.font = "12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
    msgObj.style.border = "0px solid " + bordercolor; //提示窗口的边框颜色
    msgObj.style.width = msgw + "px";
    msgObj.style.height = parseInt(msgh) + "px";
    msgObj.style.zIndex = zIndex + 1;

    // msgObj.style.padding="3px";
    //alert(topIndex);
    msgObj.style.top = (sHeight - msgh + 200) / 2 - 100 + topIndex + "px";
    msgObj.style.left = (sWidth - msgw) / 2 + "px";
    var title = top.document.createElement("h4");
    title.setAttribute("id", "msgTitle" + zIndex);
    title.setAttribute("align", "right");
    title.style.margin = "0";
    title.style.padding = "6px";
    title.style.background = "url(res/images/popup/titlebg.jpg) repeat-x";
    title.style.height = "23px";
    title.style.filter = "progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100);";
    title.style.opacity = "0.75";
    title.style.border = "0px solid " + bordercolor;
    //title.style.height = "18px";
    title.style.font = "12px Verdana, Geneva, Arial, Helvetica, sans-serif";
    title.style.color = "white";
    title.style.cursor = "move";
    title.innerHTML = "<span style='float:left;font-size:14px;font-weight:bold;padding-top:6px;padding-left:8px;'>科目余额</span><a onclick='closeDIV1(" + zIndex + ");' class='aClss' style='cursor:pointer;color:#FFFFFF;'><img src='res/images/popup/Return.jpg' border='0'/></a>";
    title.onmousedown = function() {
        startDrag(this);
    }
    title.onmouseup = function() {
        stopDrag(this);
    }
    title.onmousemove = function() {
        drag(this);
    }
    top.document.body.appendChild(msgObj);
    top.document.getElementById("msgDiv" + zIndex).appendChild(title);
    var iframe = top.document.createElement("iframe");
    iframe.style.width = msgw + 'px';
    iframe.style.height = msgh + 'px';
    iframe.style.background = "#CCC";
    iframe.style.border = '0';
    iframe.setAttribute("id", "ifNoticeAdd" + zIndex);
    iframe.setAttribute("scrolling", "no");
    iframe.setAttribute("iframeborder", "0");
    iframe.setAttribute("norsesize", "no");
    iframe.src = iframeSrc;

    top.document.getElementById("msgDiv" + zIndex).appendChild(iframe);
}
//可以打包为js文件;
var x0 = 0, y0 = 0, x1 = 0, y1 = 0;
var offx = 6, offy = 6;
var moveable = false;
var hover = '#6699BB', normal = 'slategray'; //color;
var index = 10000; //z-index;
//开始拖动;
//鼠标拖动
function startDrag(obj) {
    //锁定标题栏;
    obj.setCapture();
    //定义对象;
    var win = obj.parentNode;
    var sha = win.nextSibling;
    //记录鼠标和层位置;
    x0 = top.event.clientX;
    y0 = top.event.clientY;
    x1 = parseInt(win.style.left);
    y1 = parseInt(win.style.top);
    //记录颜色;
    normal = obj.style.backgroundColor;
    //改变风格;
    obj.style.backgroundColor = hover;
    win.style.borderColor = hover;
    obj.nextSibling.style.color = hover;
    obj.style.left = x1 + offx;
    obj.style.top = y1 + offy;
    moveable = true;
}
//拖动;
function drag(obj) {
    var win = obj.parentNode;
    var sha = win.nextSibling;
    if (moveable) {
        win.style.left = x1 + top.event.clientX - x0;
        win.style.top = y1 + top.event.clientY - y0;
        obj.style.left = parseInt(win.style.left) + offx;
        obj.style.top = parseInt(win.style.top) + offy;
    }
}
//停止拖动;
function stopDrag(obj) {
    var win = obj.parentNode;
    var sha = win.nextSibling;
    win.style.borderColor = normal;
    obj.style.backgroundColor = normal;
    obj.nextSibling.style.color = normal;
    obj.style.left = obj.parentNode.style.left;
    obj.style.top = obj.parentNode.style.top;
    //放开标题栏;
    obj.releaseCapture();
    moveable = false;
}
//END 可以打包为js文件;

//关闭层
function closeDIV(z) {
    if (document.getElementById("bgDiv" + z)) {
        document.body.removeChild(document.getElementById("bgDiv" + z));
        document.body.removeChild(document.getElementById("msgDiv" + z));
    }
    else if (top.document.getElementById("bgDiv" + z)) {
        top.document.body.removeChild(top.document.getElementById("bgDiv" + z));
        top.document.body.removeChild(top.document.getElementById("msgDiv" + z));
    }
    else if (top.document.getElementById("bgDiv" + z)) {
        top.document.body.removeChild(top.document.getElementById("bgDiv" + z));
        top.document.body.removeChild(top.document.getElementById("msgDiv" + z));
    }

    var objIndex = top.document.getElementById('indexValue');
    if (objIndex != null) {
        topIndex = objIndex.value == '' ? '0' : objIndex.value;
    }

    topIndex = parseInt(topIndex);

    if (topIndex > 0)
        objIndex.value = topIndex - 10;
}
//取标签的绝对位置
function Offset(e) {
    var t = e.offsetTop;
    var l = e.offsetLeft;
    var w = e.offsetWidth;
    var h = e.offsetHeight;
    while (e = e.offsetParent) {
        t += e.offsetTop;
        l += e.offsetLeft;
    }
    return {
        top: t,
        left: l,
        width: w,
        height: h
    }
}